"use strict";
cc._RF.push(module, '0f3a6XzTYNL95w8m8fuuDLM', 'test');
// o1SceneBundles/hall/test/test.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var testConfig_1 = require("./testConfig");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var test = /** @class */ (function (_super) {
    __extends(test, _super);
    function test() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.bgGdi = null;
        _this.gdi = null;
        _this.oneSize = 10;
        _this.nNextTime = 1;
        _this.xyCount = 70;
        _this.falseColor = cc.color();
        _this.trueColor = cc.color();
        // LIFE-CYCLE CALLBACKS:
        // onLoad () {}
        _this.m_ary = [];
        _this.m_currOffspring = 0;
        return _this;
    }
    test.prototype.start = function () {
        this.initGame();
        this.oneOffspring();
        this.schedule(this.onNextStep.bind(this), this.nNextTime);
    };
    test.prototype.initGame = function () {
        //
        for (var i = 0; i < this.xyCount; i++) {
            if (i % 10 == 0) {
                this.bgGdi.lineWidth = 1.5;
            }
            else {
                this.bgGdi.lineWidth = 1;
            }
            this.bgGdi.moveTo(0, i * this.oneSize);
            this.bgGdi.lineTo(this.oneSize * this.xyCount, i * this.oneSize);
            this.bgGdi.moveTo(i * this.oneSize, 0);
            this.bgGdi.lineTo(i * this.oneSize, this.oneSize * this.xyCount);
            this.bgGdi.stroke();
            this.m_ary[i] = [];
            for (var j = 0; j < this.xyCount; j++) {
                this.m_ary[i][j] = false;
                this.showOne(i, j, false);
            }
        }
        this.bgGdi.lineWidth = 1.5;
        this.bgGdi.moveTo(0, this.xyCount * this.oneSize);
        this.bgGdi.lineTo(this.oneSize * this.xyCount, this.xyCount * this.oneSize);
        this.bgGdi.moveTo(this.xyCount * this.oneSize, 0);
        this.bgGdi.lineTo(this.xyCount * this.oneSize, this.oneSize * this.xyCount);
        this.bgGdi.stroke();
        this.gdi.stroke();
        //
    };
    test.prototype.isCanLife = function (i, j, currLife, srcArray) {
        var roundCount = 0;
        for (var x = i - 1; x <= i + 1; x++) {
            for (var y = j - 1; y <= j + 1; y++) {
                if (srcArray[x] && srcArray[x][y]) {
                    if (x == i && y == j)
                        continue;
                    roundCount++;
                }
            }
        }
        if (roundCount == 3)
            return true;
        if (roundCount == 2)
            return currLife;
        return false;
    };
    //第一代
    test.prototype.oneOffspring = function () {
        var xy = Math.floor(this.xyCount / 2);
        var ary = testConfig_1.getRankInit(xy - 40, xy + 20, 50);
        for (var i = 0; i < ary.length; i++) {
            var x = ary[i].i;
            var y = ary[i].j;
            this.m_ary[x][y] = true;
            this.showOne(x, y, true);
        }
        this.gdi.stroke();
        this.m_currOffspring = 1;
    };
    test.prototype.onNextStep = function () {
        var srcArray = JSON.parse(JSON.stringify(this.m_ary));
        for (var i = 0; i < this.xyCount; i++) {
            for (var j = 0; j < this.xyCount; j++) {
                var curLife = this.m_ary[i][j];
                this.m_ary[i][j] = this.isCanLife(i, j, this.m_ary[i][j], srcArray);
                if (curLife != this.m_ary[i][j]) {
                    this.showOne(i, j, this.m_ary[i][j]);
                }
            }
        }
        this.gdi.stroke();
        this.m_currOffspring++;
    };
    test.prototype.showOne = function (i, j, isLife) {
        this.gdi.fillColor = isLife ? this.trueColor : this.falseColor;
        this.gdi.fillRect(i * this.oneSize + 1, j * this.oneSize + 1, this.oneSize - 2, this.oneSize - 2);
    };
    __decorate([
        property(cc.Graphics)
    ], test.prototype, "bgGdi", void 0);
    __decorate([
        property(cc.Graphics)
    ], test.prototype, "gdi", void 0);
    __decorate([
        property()
    ], test.prototype, "oneSize", void 0);
    __decorate([
        property()
    ], test.prototype, "nNextTime", void 0);
    __decorate([
        property()
    ], test.prototype, "xyCount", void 0);
    __decorate([
        property(cc.Color)
    ], test.prototype, "falseColor", void 0);
    __decorate([
        property(cc.Color)
    ], test.prototype, "trueColor", void 0);
    test = __decorate([
        ccclass
    ], test);
    return test;
}(cc.Component));
exports.default = test;

cc._RF.pop();